<template>
	<view class="page" :style="{'min-height':h+'px','padding-top':mt+'px'}">
		<!-- 头部 -->
		<c-nav-bar title="改签" bgColor="#007A69" leftIconColor="#ffffff"
			:titleStyle="{'fontSize': '36rpx','fontWeight': 'bold','color': '#ffffff'}"></c-nav-bar>
		<!-- 	<image class="bg" src="https://i.ringzle.com/file/20231025/87b08695ad8e42418fd81a98b2f742fe.jpg" mode="">
		</image> -->
		<view class="bg">

		</view>

		<!-- 船票信息 -->
		<view class="box ship">
			<view class="s_top">
				<view class="st_left">
					<text>{{item.date}}</text>
					<text>{{item.week}}</text>
				</view>
				<view class="st_right" v-if="item.timeMemosStr||item.timeMemos">
					<image src="@/static/my/icon_time.png"></image>
					<text>{{item.timeMemosStr||item.timeMemos}}</text>
				</view>
			</view>
			<view class="s_middle">
				<view class="sm_left">
					<text>{{item.time}}</text>
					<view class="fromto">
						<image src="@/static/index/steamerTicket/icon_line2.png"></image>
						<view class="fo_addr">
							<text>{{item.startPortName}}</text>
							<text>{{item.endPortName}}</text>
						</view>
					</view>
				</view>
				<view class="sm_img" @tap="toAddress">
					<image src="https://i.ringzle.com/file/20231025/6f507aa673cb412880fd6181c38d7e1b.png"></image>
					<text>港口地址</text>
				</view>
			</view>
			<view class="s_bottom">
				<view>
					<text>{{item.lineNum+''+item.sx}}</text>
					<text>{{item.clxm}}</text>
				</view>
				<view v-if="item.buyTicketType==2">
					<!-- <text>车船联票：<span v-if="item.busStartTime">开车时间{{item.busStartTime}}</span></text> -->
					<text v-if="item.busStartTime"><span>开车时间{{item.busStartTime}}</span></text>
					<text v-if="item.sailTime">开船时间：{{item.sailTime}}</text>
				</view>
			</view>
		</view>
		<!-- 全选 -->
		<view class="box allselect">
			<!-- <view class="as_top">
					<image src="https://fsy.shengsi.gov.cn/file/20240906/119a9318c011420ba8b7677bc12fbf00.png" mode="" v-if="!isAll" @tap="allSelectOrNot"></image>
					<image src="@/static/my/icon_select.png" mode="" v-else @tap="allSelectOrNot"></image>
					<text>全选</text>
				</view> -->
			<!-- <view class="line"></view> -->
			<view class="as_item" v-for="(passenger,index) in passengers" :key="index">
				<image src="https://fsy.shengsi.gov.cn/file/20240906/119a9318c011420ba8b7677bc12fbf00.png" v-if="!passenger.isSelect"
					@tap="selectItem(passenger,index)"></image>
				<image src="https://i.ringzle.com/file/20240221/afe4259bb3484ca1889cb96341f05a10.png" v-else
					@tap="selectItem(passenger,index)"></image>
				<view class="asi_info">
					<view class="asii_top">
						<view class="asiit_left">
							<text>{{passenger.passName}}</text>
							<view>{{personTypeCfg[passenger.priceType]||''}}</view>
						</view>
						<view class="asiit_right">
							<text>￥{{passenger.realFee}}</text>
						</view>
					</view>
					<view class="asii_text">
						<text>{{personCardCfg[passenger.credentialType]||'证件号'}} {{passenger.credentialNum}}</text>
					</view>
					<view class="asii_text">
						<text>{{item.startPortName}} - {{item.endPortName}}</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 温馨提示 -->
		<view class="wxts">
			<text class="title">温馨提示</text>
			<text class="text">已取票、已退票或已改签的船票无法改签。每张船票只能改签一次，改签成功后的车票不能再次改签。</text>
		</view>
		<!-- 确定改签 -->
		<view class="bottom">
			<view class="btn" @tap="sureChangeTicket">确定改签</view>
		</view>
		<u-toast ref="uToast"></u-toast>

	</view>
</template>

<script>
	export default {
		name: 'changeTicket',
		data() {
			return {
				h: uni.getWindowInfo().windowHeight - 60,
				mt: uni.getSystemInfoSync().statusBarHeight + 44,
				titleStyle: {
					fontSize: '36rpx',
					fontWeight: "bold",
					color: "#FFFFFF"
				},
				item: null,
				ocfg: this.$ocfg,
				week: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
				isAll: false,
				passengers: [],
				portCfg:{
					'1010':{lng:122.425225,lat:30.738996,title:'李柱山码头',address:'浙江省舟山市嵊泗县李五线嵊泗列岛风景名胜区',telphone:'(0580)5078323/(0580)5083723'},
					'1011':{lng:122.425225,lat:30.738996,title:'李柱山码头',address:'浙江省舟山市嵊泗县李五线嵊泗列岛风景名胜区',telphone:'(0580)5078323/(0580)5083723'},
					'1012':{lng:122.465182,lat:30.729425,title:'小菜园客运码头',address:'浙江省舟山市嵊泗县海滨东路265号',telphone:'(0580)5070342'},
					'1013':{lng:122.699829,lat:30.846601,title:'嵊泗(绿华)',address:'浙江省舟山市嵊泗县花鸟岛内(东侧)',telphone:'(0580)5596999'},
					'1014':{lng:122.699829,lat:30.846601,title:'花鸟客运码头',address:'浙江省舟山市嵊泗县花鸟岛内(东侧)',telphone:'(0580)5596999'},
					'1015':{lng:122.699829,lat:30.846601,title:'嵊泗(毕下)',address:'浙江省舟山市嵊泗县花鸟岛内(东侧)',telphone:'(0580)5596999'},
					'1016':{lng:122.80995,lat:30.724053,title:'嵊山北码头',address:'浙江省舟山市嵊泗县嵊山枸杞景区内(东侧)',telphone:''},
					'1017':{lng:122.757875,lat:30.708894,title:'枸杞岛干斜码头',address:'浙江省舟山市嵊泗县轧轧洞',telphone:''},
					'1018':{lng:122.092689,lat:30.591915,title:'大洋站码头',address:'浙江省舟山市嵊泗县大洋镇后门村',telphone:''},
					'1019':{lng:122.52484,lat:30.70048,title:'五龙',address:'浙江省舟山市嵊泗县沿边路73号附近',telphone:''},
					'1020':{lng:122.229553,lat:30.241081,title:'岱山竹屿码头',address:'浙江省舟山市岱山县526国道与采霞路交叉口东140米',telphone:''},
					'1022':{lng:122.118523,lat:30.138428,title:'舟山三江码头',address:'浙江省舟山市定海区马岙镇定马线',telphone:'(0580)8081001'},
					'1027':{lng:122.371892,lat:29.951295,title:'朱家尖蜈蚣峙码头',address:'浙江省舟山市普陀区朱家尖镇普渡路4号',telphone:'(0580)3889090'},
					'1028':{lng:122.134244,lat:30.600722,title:'沈家湾客运码头',address:'浙江省舟山市嵊泗县洋山深水港东端',telphone:'(0580)5298323'},
					'1030':{lng:122.285296,lat:30.433887,title:'衢山客运中心',address:'浙江省舟山市岱山县蓬莱路91号',telphone:'(0580)4372611'},
					'1031':{lng:122.177286,lat:30.342718,title:'燕窝山客运中心',address:'浙江省舟山市岱山县燕窝山码头',telphone:''},
					'1034':{lng:122.55166,lat:30.665056,title:'黄龙码头',address:'浙江省舟山市嵊泗县',telphone:''},
					'1036':{lng:121.317611,lat:31.194301,title:'上海长途客运虹桥站',address:'上海市闵行区申虹路298号',telphone:'(021)51245555'},
					'1041':{lng:121.53371,lat:29.861731,title:'宁波汽车南站',address:'浙江省宁波市海曙区甬水桥路408号',telphone:'(0574)87133561'},
					'1046':{lng:121.501345,lat:31.208135,title:'上海南浦旅游集散中心',address:'上海市黄浦区外马路1588号',telphone:'4008872626'},
					'1053':{lng:122.216957,lat:30.255614,title:'岱山县长途客运中心',address:'浙江省舟山市岱山县衢山大道999号',telphone:'(0580)4472521'},
					'1054':{lng:122.099067,lat:30.297928,title:'岱山旅游集散中心',address:'岱山520路,岱山502路,岱山501路',telphone:''}
				}
			}
		},
		onLoad(option) {
			if (option.item) {
				this.item = JSON.parse(option.item);
				this.item.date = new Date(this.item.sailDate).Format('MM月dd日');
				this.item.week = this.week[new Date(this.item.sailDate).getDay()];
				this.item.time = new Date(new Date().Format('yyyy-MM-dd') + ' ' + this.item.sailTime).Format('hh:mm');
				this.passengers = this.item.detailDTOList;
				this.passengers.forEach((d, i) => this.$set(this.passengers[i], 'isSelect', false));
			}
		},
		methods: {
			//全选/反选
			allSelectOrNot() {
				this.isAll = !this.isAll;
				this.passengers.forEach((d, i) => this.$set(this.passengers[i], 'isSelect', this.isAll));
				this.passengers.forEach((d, i) => {
					if (d.itemState == 5) this.$set(this.passengers[i], 'isSelect', false)
				});
			},
			selectItem(item, index) {
				if (item.itemState == 5) return this.$showToast('该乘客已改签');
				this.passengers.forEach((p, i) => {
					this.$set(this.passengers[i], 'isSelect', i == index ? true : false);
				})

				// this.$set(this.passengers[index],'isSelect',!this.passengers[index].isSelect);
				// let snum = this.passengers.filter(p=>p.isSelect==true).length;
				// if(snum==this.passengers.length) this.isAll = true;
				// else this.isAll = false;
			},
			//跳转港口地址
			toAddress() {
				let departPort = this.portCfg['10'+this.item.startPortNo]||'';
				let arrivePort = this.portCfg['10'+this.item.endPortNo]||'';
				if(!departPort&&!arrivePort) return this.$showToast('暂无港口地址');
				uni.navigateTo({
					url: '/pagesIndex/steamerTicket/portAddress?departPort=' + JSON.stringify(departPort) + "&arrivePort=" + JSON.stringify(arrivePort)
				})
			},
			// 确定改签
			sureChangeTicket() {
				if (!this.passengers.find(p => p.isSelect == true)) return this.$showToast('请选择乘客进行改签');
				
				this.$api.post('/api/travel/api/ship/order/wouldAlter',{
					 orderId:this.item.orderId,
					 orderItemId: this.passengers.find(p => p.isSelect == true).id||''
				}).then(res=>{
					if(res.data.code===0){
						uni.setStorageSync('change_ticket_info', JSON.stringify({
							orderId: this.item.orderId,
							orderItemId: this.passengers.find(p => p.isSelect == true).id,
							passengers: this.passengers.filter(p => p.isSelect == true),
							orderDetailId: this.passengers.find(p => p.isSelect == true).id,
							startPortName: this.item.startPortName,
							startPortNo: this.item.startPortNo,
							endPortName: this.item.endPortName,
							endPortNo: this.item.endPortNo,
							buyTicketType: this.item.buyTicketType
						}))
						uni.navigateTo({
							url: '/pagesMy/shipTicketOrder/changeTicketQuery'
						})
					}else this.$showModal(res.data.msg);
				})
			}
		}
	}
</script>

<style scoped lang="less">
	.page {
		background: #F5F8FA;
		display: flex;
		align-items: center;
		flex-direction: column;
		padding-bottom: 140rpx;

		.bg {
			// width: 100%;
			// height: 702rpx;
			// position: absolute;
			// top: 0;
			// left: 0;
			// z-index: 0;
			height: 700rpx;
			position: fixed;
			// top: 44px;
			// z-index: 1;
			width: 100%;
			background-image: linear-gradient(to bottom, #007A69, #007A69, #F5F8FA);
		}

		.box {
			width: calc(100% - 88rpx);
			background: #FFFFFF;
			border-radius: 16rpx;
			padding: 30rpx 20rpx;
			position: relative;
		}

		.ship {
			margin-top: 48rpx;

			.s_top {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.st_left {
					text {
						font-size: 30rpx;
						font-family: PingFang-SC-Bold, PingFang-SC;
						font-weight: bold;
						color: #111111;

						&:last-child {
							margin-left: 16rpx;
						}
					}
				}

				.st_right {
					display: flex;
					align-items: center;

					image {
						width: 28rpx;
						height: 28rpx;
					}

					text {
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #999999;
						margin-left: 16rpx;
					}
				}
			}

			.s_middle {
				margin-top: 28rpx;
				display: flex;
				justify-content: space-between;

				.sm_left {
					display: flex;

					&>text {
						font-size: 40rpx;
						font-family: PingFang-SC-Bold, PingFang-SC;
						font-weight: bold;
						color: #333333;
					}

					.fromto {
						display: flex;
						align-items: center;
						margin-left: 40rpx;

						&>image {
							width: 8rpx;
							height: 68rpx;
						}

						.fo_addr {
							margin-left: 20rpx;
							display: flex;
							flex-direction: column;

							text {
								font-size: 30rpx;
								font-family: PingFang-SC-Bold, PingFang-SC;
								font-weight: bold;
								color: #333333;

								&:last-child {
									margin-top: 30rpx;
								}
							}
						}
					}
				}

				.sm_img {
					width: 178rpx;
					height: 128rpx;
					position: relative;

					image {
						width: 100%;
						height: 100%;
					}

					text {
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #5778A8;
						position: absolute;
						right: 24rpx;
						bottom: 31rpx;
					}
				}
			}

			.s_bottom {
				border-top: 1rpx solid #EFEFEF;
				padding-top: 30rpx;

				&>view {
					display: flex;
					align-items: center;
					margin-top: 16rpx;

					&:first-child {
						margin-top: 0;
					}

					text {
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #777777;
						margin-left: 16rpx;

						&:first-child {
							margin-left: 0;
						}
					}
				}
			}
		}

		.line {
			width: 100%;
			height: 1rpx;
			background: #EFEFEF;
			margin-top: 36rpx;
		}

		.allselect {
			margin-top: 15rpx;

			.as_top {
				display: flex;
				align-items: center;

				image {
					width: 40rpx;
					height: 40rpx;
				}

				text {
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #666666;
					margin-left: 20rpx;
				}
			}

			.as_item {
				margin-top: 30rpx;
				display: flex;

				&>image {
					width: 40rpx;
					height: 40rpx;
				}

				.asi_info {
					width: calc(100% - 40rpx);
					padding-left: 26rpx;

					.asii_top {
						display: flex;
						align-items: center;
						justify-content: space-between;

						.asiit_left {
							display: flex;
							align-items: center;

							&>text {
								font-size: 30rpx;
								font-family: PingFang-SC-Bold, PingFang-SC;
								font-weight: bold;
								color: #333333;
							}

							&>view {
								width: 88rpx;
								height: 36rpx;
								background: #F5F8FA;
								border-radius: 8rpx;
								line-height: 36rpx;
								text-align: center;
								font-size: 24rpx;
								font-family: PingFangSC-Regular, PingFang SC;
								font-weight: 400;
								color: #94A9C8;
								margin-left: 15rpx;
							}
						}

						.asiit_right {
							text {
								font-size: 28rpx;
								font-family: PingFangSC-Regular, PingFang SC;
								font-weight: 400;
								color: #FF4141;
							}
						}
					}

					.asii_text {
						margin-top: 20rpx;

						text {
							font-size: 24rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #666666;
						}
					}
				}
			}
		}

		.wxts {
			margin-top: 64rpx;
			display: flex;
			flex-direction: column;
			padding: 0 30rpx;
			z-index: 1;

			.title {
				font-size: 24rpx;
				font-family: PingFang-SC-Bold, PingFang-SC;
				font-weight: bold;
				color: #FF7D01;
			}

			.text {
				font-size: 24rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #FF7D01;
				margin-top: 16rpx;
			}
		}

		.bottom {
			width: calc(100% - 60rpx);
			height: 120rpx;
			background: #FFFFFF;
			padding: 0 30rpx;
			position: fixed;
			bottom: 0;
			display: flex;
			align-items: center;
			justify-content: center;

			.btn {
				width: 100%;
				height: 80rpx;
				border-radius: 46rpx;
				// border: 1rpx solid #007A69;
				background-color: #007A69;
				line-height: 80rpx;
				text-align: center;
				font-size: 32rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
				letter-spacing: 2rpx;
			}
		}
	}
</style>